import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class ClipPage extends StatefulWidget {
  const ClipPage({Key? key}) : super(key: key);

  @override
  _ClipPageState createState() => _ClipPageState();
}

class _ClipPageState extends State<ClipPage> {
  bool _selected = false;
  int index = -1;
  var filterList = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text(widget.runtimeType.toString()),
      ),
      /**
       * Chip
        InputChip
        ChoiceChip
        FilterChip
        ActionChip
       */
      body: ListView(
        children: [
          const Chip(label: Text("Chip")),
          const InputChip(label: Text("InputChip")),
          // ChoiceChip(label: Text("ChoiceChip")),
          const RawChip(
            label: Text("RawChip"),
          ),
          const RawChip(
            label: Text("RawChip isEnabled"),
            isEnabled: false,
          ),
          const RawChip(
            avatar: CircleAvatar(
              child: Text('孟'),
            ),
            label: Text('老孟'),
          ),
          const RawChip(
            label: Text('老孟'),
            labelStyle: TextStyle(color: Colors.blue),
            labelPadding: EdgeInsets.symmetric(horizontal: 10),
          ),
          RawChip(
            label: const Text('老孟'),
            onDeleted: () {
              if (kDebugMode) {
                print('onDeleted');
              }
            },
            deleteIcon: const Icon(Icons.delete),
            deleteIconColor: Colors.red,
            deleteButtonTooltipMessage: '删除',
          ),
          RawChip(
            label: const Text('老孟'),
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
            backgroundColor: Colors.blue,
            padding: const EdgeInsets.symmetric(vertical: 10),
          ),
          const RawChip(
            label: Text('老孟'),
            elevation: 8,
            shadowColor: Colors.blue,
          ),
          RawChip(
            label: const Text('老孟'),
            selected: _selected,
            elevation: 8,
            shadowColor: Colors.blue,
            onSelected: (v) {
              setState(() {
                _selected = v;
              });
            },
            selectedColor: Colors.blue,
            selectedShadowColor: Colors.red,
          ),
          RawChip(
            label: const Text('无√'),
            selected: _selected,
            showCheckmark: false,
            checkmarkColor: Colors.red,
            onSelected: (v) {
              setState(() {
                _selected = v;
              });
            },
          ),
          RawChip(
            label: const Text('按住阴影'),
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
            onPressed: () {
              if (kDebugMode) {
                print('onPressed');
              }
            },
            pressElevation: 12,
          ),
          ChoiceChip(
            label: const Text('老孟'),
            selected: _selected,
            onSelected: (v) {
              setState(() {
                setState(() {
                  _selected = v;
                });
              });
            },
          ),
          Column(
            children: [
              Wrap(
                spacing: 10,
                children: List.generate(
                    10,
                    (index) => FilterChip(
                        selected: filterList.contains("$index"),
                        label: Text("老孟$index"),
                        onSelected: (v) {
                          setState(() {
                            if (v) {
                              filterList.add('$index');
                            } else {
                              filterList.removeWhere((f) {
                                return f == '$index';
                              });
                            }
                          });
                        })),
              )
            ],
          ),
          Text("选择了 ${filterList.join(",")}"),
          const SizedBox(
            height: 20,
          ),
          ActionChip(
              avatar: CircleAvatar(
                backgroundColor: Colors.grey.shade800,
                child: const Text('孟'),
              ),
              label: const Text('老孟'),
              onPressed: () {
                if (kDebugMode) {
                  print("onPressed");
                }
              })
        ],
      ),
    );
  }
}
